use "build/output/main_panel.dta", clear
tsset coin_id date
sort coin_id date

********************************************************************************
* Regression: stablecoin interset rate from FTX on other observables
********************************************************************************

eststo clear
eststo: reg margin_aprFTX funding_apr if coin == "USDT", vce(cluster wdate)
estadd scalar adjR2 = round(`e(r2_a)',0.01), replace
estadd local month_fe "No"
estadd local coin_fe "No"

eststo: reg margin_aprFTX funding_apr i.mdate if coin == "USDT" , vce(cluster wdate)
estadd scalar adjR2 = round(`e(r2_a)',0.01), replace
estadd local month_fe "Yes"
estadd local coin_fe "No"

eststo: reg margin_aprFTX funding_apr l.margin_aprFTX iv_btc r_btc i.mdate if coin == "USDT" , vce(cluster wdate)
estadd scalar adjR2 = round(`e(r2_a)',0.01), replace
estadd local month_fe "Yes"
estadd local coin_fe "No"

eststo: reg margin_aprFTX funding_apr, vce(cluster wdate)
estadd scalar adjR2 = round(`e(r2_a)',0.01), replace
estadd local month_fe "No"
estadd local coin_fe "No"

eststo: reg margin_aprFTX funding_apr i.mdate i.coin_id, vce(cluster wdate)
estadd scalar adjR2 = round(`e(r2_a)',0.01), replace
estadd local month_fe "Yes"
estadd local coin_fe "Yes"

eststo: reg margin_aprFTX funding_apr l.margin_aprFTX iv_btc r_btc i.mdate i.coin_id , vce(cluster wdate)
estadd scalar adjR2 = round(`e(r2_a)',0.01), replace
estadd local month_fe "Yes"
estadd local coin_fe "Yes"

esttab, drop(*.mdate *coin_id _cons) star(* 0.10 ** 0.05 *** 0.01)
esttab using "analysis/output_tables/regression_stablecoin_r_on_y.tex", replace booktabs label drop(*.mdate _cons *coin_id) ///
	prehead(\begin{tabular}{l S S S S S S} \toprule) ///
	posthead(\midrule) postfoot(\bottomrule\end{tabular}) ///
	style(tex) substitute(\_ _) star  b(2) t(2) r2(2) ///
	nomtitles /// 
	varlabels(funding_apr "\$\text{Futures Funding Rate}_{t}$" r_btc "\$R^{\textit{BTC}}_{t}\$" iv_btc "\$\text{BTC Implied Volatility}_{t}\$" L.margin_aprFTX "\$\text{Stablecoin Lending Rate}_{t-1}\$") ///
	interaction(" $\times$ ") /// 
	star(* 0.10 ** 0.05 *** 0.01) ///
	mgroups("USDT" "USDT and DAI", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
	stats(N r2 month_fe coin_fe, fmt(%9.0fc 2) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}") labels(`"\$N\$"' `"\(R^{2}\)"' `"Month FE"' `"Coin FE"'))
